﻿

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>选择图片</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <style>
    body{padding:10px; font-size:14px; background:#fff; width:95%; margin:0 auto; font-size:14px; line-height:20px; }
    p{margin-bottom:10px;}
    input{border:1px solid #999; padding:5px 10px; margin:0 10px 10px 0;}
  </style>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <form class="layui-form" action="" lay-filter="component-form-group">
                        <div class="layui-btn-group test-table-operate-btn" style="display:none;">
                            <input id="uidsub" class="form-control" name="uid" type="hidden" value="">
                            <button class="layui-btn" id="saveBtn" data-type="getCheckData"></button>
                        </div>
                        <div class="layui-card-body" id="pic_content">
                         </div>
                   </form>
                </div>
            </div>
        </div>
    </div>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../layuiadmin/js/jquery.min2.1.4.js"></script>
    <script>
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var type = getUrlParam('type');
        var cxordxs = getUrlParam('cxordx');
        $.ajax({
            url: 'ashx/list.ashx?type=getlist_pic&lxtype=' + type + '&cxordx=' + cxordxs,
            type: 'GET',
            success: function (data) {
                var str = "";
                for (var i = 0; i < data.data.length; i++) {
                    //if (i == 0) {
                        str += "<div class='layui-col-md1' style ='margin:20px 30px 20px 10px;'>";
                        str += "<div class='layadmin-homepage-pad-ver' style='text-align:center'>";
                        str += "<img width='150' height='150' class='layadmin-homepage-pad-img' src='" + data.data[i].imgurl + "'>";
                        str += "<h4 class='layadmin-homepage-font' id='lxbh'>" + data.data[i].name + "</h4>";
                        str += "<p class='layadmin-homepage-min-font' id='lxmc'>" + data.data[i].describe + "</p>";
                        str += "<input type='checkbox' lay-skin='primary' name='indicators' lay-filter='indicators' value=" + data.data[i].id + ',' + data.data[i].name + ',' + data.data[i].imgurl + ',' + data.data[i].describe + " />";
                        str += "</div>";
                        str += "</div>";
                    //}
                    //else {
                    //    //str += "<div class='layui-col-md1  layui-col-lg-offset1'>";
                    //    str += "<div class='layui-col-md1' style ='margin:20px 20px 20px 20px;'>";
                    //    str += "<div class='layadmin-homepage-pad-ver' style='text-align:center'>";
                    //    str += "<img width='150' height='150' class='layadmin-homepage-pad-img' src='" + data.data[i].imgurl + "'>";
                    //    str += "<h4 class='layadmin-homepage-font' id='lxbh'>" + data.data[i].name + "</h4>";
                    //    str += "<p class='layadmin-homepage-min-font' id='lxmc'>" + data.data[i].describe + "</p>";
                    //    str += "<input type='checkbox' lay-skin='primary' name='indicators' lay-filter='indicators' value=" + data.data[i].id + ',' + data.data[i].name + ',' + data.data[i].imgurl + ',' + data.data[i].describe + " />";
                    //    str += "</div>";
                    //    str += "</div>";
                    //}
                }
                $("#pic_content").append(str);
                layui.use(['layer', 'element', 'form'], function () {
                    var $ = layui.jquery,
                        layer = layui.layer,
                        form = layui.form,
                        element = layui.element;
                     form.on('checkbox(indicators)', function (data) {
                        $("input[name='indicators']").prop("checked", false);   //全部取消选中
                        $(this).prop("checked", true);                          //勾选当前选中的选择框     
                        form.render('checkbox');
                    });
                    form.render('checkbox');
                    element.init();
                });
            }
        })
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table'], function () {
            var admin = layui.admin
                , table = layui.table;
            /*点击确定*/
            $("#saveBtn").on('click', function () {
                var geturl = '';
                $('input[type=checkbox]:checked').each(function () {
                    geturl=$(this).val();
                });
                if (geturl == "" || geturl == null) {
                    layer.msg('请选择数据', { icon: 7 }); return;
                }
                else {
                    $("#uidsub").val(geturl);
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
        });
    </script>
</body>
</html>
